package com.tl.khadmin.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.poi.hssf.util.HSSFColor.RED;
import org.springframework.stereotype.Service;

import com.tl.khadmin.bean.Order;
import com.tl.khadmin.bean.OrderAftersale;
import com.tl.khadmin.bean.OrderException;
import com.tl.khadmin.bean.OrderRefund;
import com.tl.khadmin.bean.Staff;
import com.tl.khadmin.bean.Supplier;
import com.tl.khadmin.mapper.OrderExceptionMapper;
import com.tl.khadmin.mapper.OrderMapper;
import com.tl.khadmin.mapper.OrderRefundMapper;
import com.tl.khadmin.page.Page;
import com.tl.khadmin.service.OrderExceptionIService;
import com.tl.khadmin.service.OrderRefundIService;
import com.tl.khadmin.util.CommonUtil;
import com.tl.khadmin.util.Constant;
import com.tl.khadmin.util.PutParamUtil;

@Service
public class OrderExceptionServiceImpl implements OrderExceptionIService {

	@Resource
	private OrderExceptionMapper orderExceptionMapper;
	@Resource
	private OrderMapper orderMapper;

	@Override
	public Page<OrderException> showByPage(HttpSession session, Integer pageNum, Integer pageSize, Map<String, Object> params) {
		Page<OrderException> page = new Page<OrderException>(pageNum, pageSize);
		params.put("page", page);
		Supplier supplier = (Supplier) session.getAttribute(Constant.USER_SUPPLIER);
        PutParamUtil.setParamIsInterior(supplier, params);	//设置查询供应商数据范围 
		List<OrderException> list = orderExceptionMapper.showByPage(params);
		page.setResult(list);
		return page;
	}

	@Override
	public String restore(Integer id) {
		if (id == null) {
			return CommonUtil.returnMapResultToJson("fail", "参数错误");
		}
		OrderException oe = orderExceptionMapper.selectByPrimaryKey(id);
		//是否已解决，1否，2是
		if(oe.getIsSolve() == 2) {
			return CommonUtil.returnMapResultToJson("fail", "请勿重复操作");
		}
		Order order = new Order();
		order.setId(oe.getOrderId());
		order.setAbnormalStatus(1);
		if(orderMapper.updateByPrimaryKeySelective(order) == 1) {
			OrderException temp = new OrderException();
			temp.setId(id);
			temp.setIsSolve(2);
			int row = orderExceptionMapper.updateByPrimaryKeySelective(temp);
			return CommonUtil.returnMapResultByRows(row, "提交成功", "提交失败");
		}
		return CommonUtil.returnMapResultToJson("fail", "提交失败");
	}

}
